package com.shop2cn.iapi.sqdistributor.testcase;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqdistributor.parameter.request.SetDistributionConfigReq;
import com.shop2cn.iapi.sqdistributor.parameter.request.pojo.DistributorLevelCommissionConfigVo;
import com.shop2cn.iapi.sqdistributor.service.SetDistributionConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.sqdistributor.CommisionRate;
import com.ymttest.database.model.sqdistributor.DistributionConfig;
import com.ymttest.database.sqlwapper.sqdistributor.CommisionRateWrapper;
import com.ymttest.database.sqlwapper.sqdistributor.DistributionConfigWrapper;
import com.ymttest.utils.DataUtil;

public class Ts_SetDistributionConfig {
	
	//java接口
	private static SetDistributionConfigReq setDistributionConfigReq;
	private static SetDistributionConfigCall setDistributionConfigCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户的分销员配置");
	}

	@Before
	public void caseUp() {
		setDistributionConfigReq = new SetDistributionConfigReq();
		setDistributionConfigCall = new SetDistributionConfigCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setDistributionConfigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public void verifyDb() throws Exception {
		
		DistributionConfigWrapper distributionConfigWrapper = new DistributionConfigWrapper();
		
		DistributionConfig actualResult = distributionConfigWrapper
				.selectByMerchantId(setDistributionConfigReq.getMerchantId());
		
		Logger.comment("验证distribution_config表");

		Logger.verifyEquals(setDistributionConfigReq.getMerchantId(),
				actualResult.getMerchant_id(), "验证Merchant_id");
		Logger.verifyEquals(
				setDistributionConfigReq.getUserDistributorBindRuleType(),
				actualResult.getUser_distributor_bind_rule_type(),
				"验证User_distributor_bind_rule_type");
		Logger.verifyEquals(setDistributionConfigReq.getDistributionLayers(),
				actualResult.getDistribution_layers(), "验证Distribution_layers");
		Logger.verifyEquals(
				setDistributionConfigReq.getDistributionSettlementDelayDays() == null ? 0
						: setDistributionConfigReq
								.getDistributionSettlementDelayDays(),
				actualResult.getDistribution_settlement_delay_days(),
				"验证Distribution_settlement_delay_days");
		Logger.verifyEquals(
				setDistributionConfigReq.getSelfPurchaseCommission(),
				actualResult.getSelf_purchase_commission(),
				"验证Self_purchase_commission");
		
		// 如果是有效期的绑定方式，BindingEffectiveThreshold才有效
		if (setDistributionConfigReq.getUserDistributorBindRuleType() == 3) {
			Logger.verifyEquals(setDistributionConfigReq.getBindingEffectiveThreshold(),
					actualResult.getBinding_effective_threshold(), "验证BindingEffectiveThreshold");
		} else
			Logger.verifyEquals(0,
					actualResult.getBinding_effective_threshold(), "验证BindingEffectiveThreshold");
		
		verifyCommisionRateTable(actualResult.getId());
	}
	
	public void verifyCommisionRateTable(Long configId) {
		
		Logger.comment("验证commision_rate表");
		
		List<DistributorLevelCommissionConfigVo> expectList = setDistributionConfigReq.getDistributorLevelCommissionConfigVoList();
		
		CommisionRateWrapper commisionRateWrapper = new CommisionRateWrapper();
		
		List<CommisionRate> actualList = commisionRateWrapper.selectByConfigId(configId);
		
		Logger.verifyEquals(expectList.size(), actualList.size(), "验证CommisionRate的size");
		
		for (int i = 0; i < actualList.size(); i++) {
			
			CommisionRate actualResult = actualList.get(i);
			DistributorLevelCommissionConfigVo expectResult = expectList.get(i);
			
			Logger.verifyEquals(setDistributionConfigReq.getMerchantId(),
					actualResult.getMerchant_id(), "验证Merchant_id");
			Logger.verifyEquals(configId,
					actualResult.getDistribution_config_id(),
					"验证Distribution_config_id");
			Logger.verifyEquals(expectResult.getDistributorLevelIndex(),
					actualResult.getDistributor_level_index(),
					"验证Distributor_level_index");
			Logger.verifyEquals(expectResult.getDistributorLevelLabel(),
					actualResult.getDistributor_level_label(),
					"验证Distributor_level_label");
			DataUtil.verifyDecimalEquals(expectResult.getLayer1Rate(), actualResult.getLayer1_rate(), "验证Layer1_rate");
			DataUtil.verifyDecimalEquals(expectResult.getLayer2Rate(), actualResult.getLayer2_rate(), "验证Layer2_rate");
			DataUtil.verifyDecimalEquals(expectResult.getLayer3Rate(), actualResult.getLayer3_rate(), "验证Layer3_rate");
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_001() {
		Logger.start(true, "商户的分销员配置，一级分销，设置成功");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			setDistributionConfigReq.setDistributionLayers(1);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays
							.asList(distributorLevelCommissionConfigVo));
			setDistributionConfigReq.setMerchantId(501565932L);
			setDistributionConfigReq.setSelfPurchaseCommission(false);
			setDistributionConfigReq.setUserDistributorBindRuleType(3);
			setDistributionConfigReq.setBindingEffectiveThreshold(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();
			
			Logger.verifyEquals(true, setDistributionConfigCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_002() {
		Logger.start(true, "商户的分销员配置，多级分销，设置成功");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(new BigDecimal("0.0556")).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(12);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861049L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(3);
			setDistributionConfigReq.setBindingEffectiveThreshold(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(true, setDistributionConfigCall.getSuccess(),
					"验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_004() {
		Logger.start(true, "商户的分销员配置，二级返佣比例大于一级返佣比例，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig()
					.withDistributorLevelIndex(1)
					.withLayer2Rate(new BigDecimal("0.02"));

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2);

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(false);
			setDistributionConfigReq.setUserDistributorBindRuleType(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals(String.format("二级返佣比例不能大于一级返佣比例，分销等级名称：%s！",
					distributorLevelCommissionConfigVo2
							.getDistributorLevelLabel()),
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_005() {
		Logger.start(true, "商户的分销员配置，三级返佣比例大于二级返佣比例，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig()
					.withDistributorLevelIndex(1)
					.withLayer3Rate(new BigDecimal("0.02"));

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2);

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(false);
			setDistributionConfigReq.setUserDistributorBindRuleType(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals(String.format("三级返佣比例不能大于二级返佣比例，分销等级名称：%s！",
					distributorLevelCommissionConfigVo2
							.getDistributorLevelLabel()),
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_006() {
		Logger.start(true, "商户的分销员配置，普通分销等级不存在，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig()
					.withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2);

			setDistributionConfigReq.setDistributionLayers(2);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(false);
			setDistributionConfigReq.setUserDistributorBindRuleType(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("普通分销等级不存在！",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_007() {
		Logger.start(true, "商户的分销员配置，三级分销返佣比例总和超过50%，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig()
					.withDistributorLevelIndex(1)
					.withLayer1Rate(new BigDecimal("0.3")).withLayer2Rate(new BigDecimal("0.2"));

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2);

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(false);
			setDistributionConfigReq.setUserDistributorBindRuleType(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("三级分销返佣比例总和不能超过50.0%," + String.format("分销等级名称：%s！",
					distributorLevelCommissionConfigVo2
							.getDistributorLevelLabel()),
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_008() {
		Logger.start(true, "DistributionSettlementDelayDays为null，一级分销，设置成功");
		
		try {
			
			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			setDistributionConfigReq.setDistributionLayers(1);
			//setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays
							.asList(distributorLevelCommissionConfigVo1));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(1);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(true, setDistributionConfigCall.getSuccess(),
					"验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_009() {
		Logger.start(true, "setDistributorLevelCommissionConfigVoList为null，多级分销，设置失败");
		
		try {
			
//			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
//					.createStandardDistributorLevelCommissionConfig();
//
//			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
//					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);
//
//			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
//					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
//					.withLayer1Rate(new BigDecimal("5.5")).withLayer2Rate(new BigDecimal("4.5"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
//			setDistributionConfigReq
//					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
//							distributorLevelCommissionConfigVo1,
//							distributorLevelCommissionConfigVo2,
//							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("distributorLevelCommissionConfigVoList:must not be null",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_010() {
		Logger.start(true, "MerchantId为null，设置失败");
		
		try {
			
			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(new BigDecimal("0.055")).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			//setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("merchantId:must be greater than or equal to 1",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_011() {
		Logger.start(true, "SelfPurchaseCommission为null，设置失败");
		
		try {
			
			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(new BigDecimal("0.055")).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			//setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("selfPurchaseCommission:must not be null",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_012() {
		Logger.start(true, "UserDistributorBindRuleType为null，设置失败");
		
		try {
			
			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(new BigDecimal("0.055")).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(500861041L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			//setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("userDistributorBindRuleType:must be greater than or equal to 1",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_013() {
		Logger.start(true, "MerchantId不存在，设置失败");
		
		try {
			
			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(new BigDecimal("0.055")).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(1241125L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(true, setDistributionConfigCall.getSuccess(),
					"验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_014() {
		Logger.start(true, "分销比例为空，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig();

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo3 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(2)
					.withLayer1Rate(null).withLayer2Rate(new BigDecimal("0.045"));

			setDistributionConfigReq.setDistributionLayers(3);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2,
							distributorLevelCommissionConfigVo3));
			setDistributionConfigReq.setMerchantId(1241125L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals(String.format("分佣比例不能为空，分销等级名称：%s！",
					distributorLevelCommissionConfigVo3
							.getDistributorLevelLabel()),
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_015() {
		Logger.start(true, "DistributorLevelIndex为空，设置失败");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(null);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			setDistributionConfigReq.setDistributionLayers(2);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2));
			setDistributionConfigReq.setMerchantId(1241125L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("普通分销等级不存在！",
					setDistributionConfigCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributionConfig_016() {
		Logger.start(true, "DistributorLevelLabel为空，设置成功");
		
		try {

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo1 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelLabel(null);

			DistributorLevelCommissionConfigVo distributorLevelCommissionConfigVo2 = DistributorLevelCommissionConfigVo
					.createStandardDistributorLevelCommissionConfig().withDistributorLevelIndex(1);

			setDistributionConfigReq.setDistributionLayers(2);
			setDistributionConfigReq.setDistributionSettlementDelayDays(1);
			setDistributionConfigReq
					.setDistributorLevelCommissionConfigVoList(Arrays.asList(
							distributorLevelCommissionConfigVo1,
							distributorLevelCommissionConfigVo2));
			setDistributionConfigReq.setMerchantId(1241125L);
			setDistributionConfigReq.setSelfPurchaseCommission(true);
			setDistributionConfigReq.setUserDistributorBindRuleType(2);

			setDistributionConfigCall.setData(setDistributionConfigReq);
			setDistributionConfigCall.callService();

			Logger.verifyEquals(false, setDistributionConfigCall.getSuccess(),
					"验证success");
			Logger.verifyEquals(true, setDistributionConfigCall.getMsg()
					.contains("distributorLevelLabel:must not be null"),
					"验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
